.PHONY: diff clean remote

MAINFILE = <<FILENAME>>
FOLDER = <<FOLDERNAME>>
REMOTE = <<USER@DOMAIN>>

all: build/$(MAINFILE).pdf

# to build a diff from the current one to the git tag abcdxxx run "make prev=abcdxxx diff"
# similarly if building all, then run "make prev=abcdxxx"
diff:
	git show $(prev):$(MAINFILE).tex > prev.tex && \
	latexdiff prev.tex $(MAINFILE).tex > diff.tex && \
	echo -e "\n\n" && \
	texfot pdflatex -output-directory=build diff.tex && \
	echo -e "" && \
	texfot pdflatex -output-directory=build diff.tex && \
	echo -e "" && \
	rm prev.tex diff.tex

build/$(MAINFILE).pdf: $(MAINFILE).tex build/ figures/lineWithCircles.asy figures/comb.asy
	echo -e "\n\n" && \
	scp -r Makefile $(MAINFILE).tex figures $(REMOTE):$(FOLDER) && \
	ssh $(REMOTE) "cd $(FOLDER); make local" && \
	scp $(REMOTE):$(FOLDER)/build/*.pdf ./build/ && \
	echo -e "\n\n";

local: $(MAINFILE).tex build/ lineWithCircles.pdf comb.pdf
	echo -e "\n\n" && \
	texfot pdflatex -output-directory=build $(MAINFILE).tex && \
	echo -e "" && \
	texfot pdflatex -output-directory=build $(MAINFILE).tex && \
	echo -e "\n\n";

lineWithCircles.pdf: figures/lineWithCircles.asy
	asy figures/lineWithCircles.asy

comb.pdf: figures/comb.asy
	asy figures/comb.asy

build/:
	mkdir -p build

clean:
	rm -rf build/*
	rm -f prev.tex diff.tex
	rm -f lineWithCircles.pdf comb.pdf

